package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.DistributionPersonalStore;
import com.addplus.townmall.server.api.model.town.expand.DistributionPersonalStoreExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 分销申请入驻个人店铺表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface DistributionPersonalStoreMapper extends BaseAddMapper<DistributionPersonalStore> {

    /**
      * 方法描述：根据商城用户信息主键id获取对应个人店铺信息
      *
      * @author zhangjiehang
      * @param memberId 商城用户主键id
      * @return DistributionPersonalStoreExpand
      * @date 2018/9/22 上午11:34
      * @throws Exception
      */
    @Select("SELECT s.id,s.member_id,s.store_name,s.store_introduction,s.consumer_qq,s.consumer_wechat,s.consumer_hotline,m.nick_name,m.head_portrait,m.invite_member_id,d.balance FROM distribution_personal_store s \n" +
            "LEFT JOIN member m ON m.id = s.member_id AND m.is_deleted = 0 AND s.is_delete = 0\n" +
            "LEFT JOIN distribution_member d ON d.member_id = m.id AND d.is_delete = 0\n" +
            "WHERE s.member_id =#{memberId} AND s.audit_status=1")
    @Results({
            @Result(property="invite_member",column = "invite_member_id",one = @One(select = "" +
                    "com.addplus.townmall.server.api.mapper.town.MemberMapper.getMemberBaseMessage"))
    })
    DistributionPersonalStoreExpand getDistributionPersonalStoreByMemberId(@Param("memberId")Integer memberId);

    @Select("SELECT id,audit_status,apply_time,finish_time,real_name,birthday,gender,birthplace,birthplace_id,phone,email,id_card_photo,member_bank_card_id,store_name,store_introduction,consumer_hotline,consumer_qq,consumer_wechat,reason FROM distribution_personal_store WHERE is_delete=#{is_delete}")
    List<DistributionPersonalStoreExpand> getAllPersonalStoreByIsDelete(IPage page, @Param("is_delete") Integer is_delete);
}
